package com.design.pattern.state;

public class WinState implements State {

    GumballMachine gumballMachine;

    public WinState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    public void insertQuarter() {
        System.out.println("你已经投过钱了");
    }

    public void ejectQuarter() {
        System.out.println("不能退给你钱");
    }

    public void turnCrank() {
        System.out.println("不能摇动摇杆");
    }

    public void dispense() {
        System.out.println("你赢了，你将得到2个糖果");
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.releaseBall();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                System.out.println("糖果已经卖完了，下次早点来");
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        } else {
            System.out.println("糖果已经卖完了，下次早点来");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}